1. /* slmsetdb.cpp by K.Tsuru */
  2. // function ID 202 DRADIX
  3. #ifndef SN_H
  4. #include "sn.h"
  5. #endif
  6. /**************************************************
  7. SLong class
  8. Set a value by double including unsignd long, etc.
  9. ****************************************************/
  10. void SLong::SetDouble(double d){
  11. double absd = fabs(d), rdx = Radix();
  12. SetZero();
  13. if(absd < 1.0) return; // d = 0, sign = 0
  14. //This error check is not necessary because of SLong's protected function.
  15. //if( (absd >= rdx) && rdx != DRADIX) SetError(RADIX_ERR,"SL SetDouble", 202);
  16. double ulmax = (double)ULONG_MAX;
  17. if(absd < rdx){ //less than radix
  18. figure[0] = (fType)absd; // aHead = aTail = 0
  19. } else if(absd <= ulmax){
  20. ulong t = (ulong)absd;
  21. int i = 0, tf = 0; //flag to detect aTail
  22. //less than tree figures because ULONG_MAX < radix^3
  23. while(t){
  24. figure[i] = fType(t % DRADIX);
  25. if(figure[i] && !tf){ aTail = i; tf = 1; }
  26. t /= DRADIX; i++;
  27. }
  28. aHead = i-1; // i>=1 and over two figures
  29. } else {
  30. uint sz;
  31. int j, k;
  32. FigBlock r;
  33. int e = doubleToArray(absd, r, &sz);
  34. #ifndef NDEBUG
  35. assert(e > 0);
  36. // if( (e <= 0) || !r(1)){ SetSign(0); return; } // x = 0
  37. #endif
  38. k = min( (int)sz, e+1);
  39. figure.reserve(e-1);
  40. for(j = 1; j < k; j++) figure[e-j] = r(j);
  41. j = e -k + 1;
  42. while(!figure(j)) j++;
  43. aHead = (uint)e-1; aTail = (uint)j;
  44. }
  45. SetSign(d); //Set sign at last.
  46. }

slmsetdb.cpp : last modifiled at 2017/03/13 14:32:01(1,458 bytes)
created at 2017/10/07 10:26:49
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).